﻿using System;
using System.Runtime.Serialization;
 



namespace DiscoveryLogic.DataServices.DataObjects
{


    public enum AccountType
    {
        Savings = 0,
        CreditCard = 1,
        Mortgage = 2,
        Plan401k = 3,
        FiveTwoNine = 4,
        Investments = 5,
        Checking = 6,
        RetirementPlanner = 7,
        TradeHistory = 8
    }; 


    [DataContract] 
    public class Account
    {
        #region Private Variables

            private int id;
            private string name;
            private string accountNumber;
            private AccountType type;
            private double balance;
            private double minimumPayment;
            private DateTime nextPaymentDueDate;
            private double nextPaymentAmount;
            private string visualPath;
            private DateTime lastTransactionDate;
            private double lastTransactionAmount;

        #endregion

        #region Get/Set Properties

        [DataMember] 
        public int Id
        {
            get { return id; }
            set { 
                id = value;
                Notify();
            }
        }

        [DataMember]
        public string Name
            {
                get { return name; }
                set
                {
                    name = value;
                    Notify();
                }
            }
        [DataMember] 
            public string AccountNumber
            {
                get { return accountNumber; }
                set { 
                    accountNumber = value;
                    Notify();
                }
            }
        [DataMember] 
            public AccountType Type
            {
                get { return type; }
                set { 
                    type = value;
                    Notify();
                }
            }
        [DataMember] 
            public double Balance
            {
                get { return balance; }
                set { 
                    balance = value;
                    Notify();
                }
            }
        [DataMember] 
            public double MinimumPayment
            {
                get { return minimumPayment; }
                set { 
                    minimumPayment = value;
                    Notify();
                }
            }
        [DataMember] 
            public DateTime NextPaymentDueDate
            {
                get { return nextPaymentDueDate; }
                set { 
                    nextPaymentDueDate = value;
                    Notify();
                }
            }
        [DataMember] 
            public double NextPaymentAmount
            {
                get { return nextPaymentAmount; }
                set { 
                    nextPaymentAmount = value;
                    Notify();
                }
            }
        [DataMember] 
            public string VisualPath
            {
                get { return visualPath; }
                set
                {
                    visualPath = value;
                    Notify();
                }
            }
        [DataMember] 
            public DateTime LastTransactionDate
            {
                get { return lastTransactionDate; }
                set { lastTransactionDate = value; }
            }
        [DataMember] 
            public double LastTransactionAmount
            {
                get { return lastTransactionAmount; }
                set { lastTransactionAmount = value; }
            }


        #endregion

        #region Constructors

            public Account():this(0,string.Empty,AccountType.Savings,0,0,DateTime.MaxValue,0)
            {

            }
            
            public Account(int id,
                string accountNumber,
                AccountType type,
                double balance,
                double minimumPayment,
                DateTime nextPaymentDueDate,
                double nextPaymentAmount
                )
            {
                this.id = id;
                this.accountNumber = accountNumber;
                this.type = type;
                this.balance = balance;
                this.minimumPayment = minimumPayment;
                this.nextPaymentDueDate = nextPaymentDueDate;
                this.nextPaymentAmount = nextPaymentAmount;
            }

            public Account(int id,
                string name,
                string accountNumber,
                AccountType type,
                double balance,
                double minimumPayment,
                DateTime nextPaymentDueDate,
                double nextPaymentAmount,
                string visualPath,
                DateTime lastTransactionDate,
                double lastTransactionAmount
                )
            {
                this.id = id;
                this.name = name;
                this.accountNumber = accountNumber;
                this.type = type;
                this.balance = balance;
                this.minimumPayment = minimumPayment;
                this.nextPaymentDueDate = nextPaymentDueDate;
                this.nextPaymentAmount = nextPaymentAmount;
                this.visualPath = visualPath;
                this.lastTransactionDate = lastTransactionDate;
                this.lastTransactionAmount = lastTransactionAmount;
            }

        #endregion

        // A delegate type for hooking up change notifications.
        public delegate void DetailChangedEventHandler(object sender, EventArgs e); // An event that clients can use to be notified whenever the

        // elements of the list change.
        public event DetailChangedEventHandler DetailChanged;

        // Invoke the Changed event; called whenever list changes
        protected virtual void OnDetailChanged(EventArgs e)
        {
            if (DetailChanged != null)
                DetailChanged(this, e);
        }

        protected void Notify()
        {
            EventArgs args = new EventArgs();
            OnDetailChanged(args);
        }

    }
}
